let YAML = require('yamljs');
const { resolve } = require('path');
const { post, get } = require('axios');
const { getAccessToken } = require('./accsToken')



const memuObject = YAML.load(resolve(__dirname, '..', 'menu.yaml'));

async function createMenu() {
    try {
        const { access_token } = await getAccessToken();
        const url = `https://api.weixin.qq.com/cgi-bin/menu/create?access_token=${access_token}`;
        return post(url, memuObject)
    } catch (error) {
        throw error;
    }
}

async function deleteMenu() {
    try {
        const { access_token } = await getAccessToken();
        const url = `https://api.weixin.qq.com/cgi-bin/menu/delete`;
        return get(url, {
            params: {
                access_token
            }
        })
    } catch (error) {
        throw error;
    }
}

// (async ()=>{
//     // let {data: delr} = await deleteMenu();
//     // console.log(delr);

//     let {data: creater} = await createMenu();
//     console.log(creater);
// })()